import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.io.BufferedReader;
import java.io.FileReader;

/**
 * This class makes a list of edges in a given graph
 * @author Hyangjin Lee
 *
 */
public class EdgeList {
	
	private Collection<Edge> edges;
	String line = null;
	
	/**
	 * This class makes a list of edges out of the given file
	 * @param txtFile The .txt format file that contains edges
	 * @throws IOException
	 */
	public EdgeList(File txtFile) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(txtFile));
		line = br.readLine();
				
		while(line !=null)
		{

			String splitarray[] = line.split(" ");
			Vertex U = new Vertex(splitarray[0]);
			Vertex V = new Vertex(splitarray[1]);
			int weight = Integer.parseInt(splitarray[2]);
			
			edges.add(new Edge(U, V, weight));	
			
			line = br.readLine();
		}

	}
	
	@Override
	public String toString() {
		return "" + edges.iterator();
	}
	
	/**
	 * Returns the collection of edges
	 * @return The collection of the edges in the given file
	 */
	public Collection<Edge> getEdges() {
		return edges;
	}
}
